<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>数据接口</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
</head>
<body>
<div style="width:520px; height:340px; border:1px solid gray" id="container"></div>
<div id="results" style="font-size:13px; margin-top:10px;"></div>
</body>
</html>
<script type="text/javascript">
var map = new BMap.Map("container");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 15);

var options = {
    renderOptions: {
        map: map,
        autoViewport: true,
        enableDragging: true
    },
    onSearchComplete: function(results) {
        // 判断状态是否正确
        if (driving.getStatus() == BMAP_STATUS_SUCCESS) {

            var s = [];

            var path  = results.getPlan(0).getRoute(0).getPath();
            var json = "[";

            for (var i = 0; i < path.length; i++) {
            	var point = path[i];
            	json += "{"
            	json += "lat:" + point.lat;
            	json += ",";
            	json += "lng:" + point.lng;
            	json += "}";
            };
            json += "]";
            s.push(json);

            document.getElementById("results").innerHTML = s.join("");
        }
    }
};

var driving = new BMap.DrivingRoute(map, options);
driving.search("西单", "北京首都国际机场");

</script>